<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        html,
        body {
            height: 100%;
            overflow: hidden;
        }
        
        body,
        div,
        h2 {
            margin: 0;
            padding: 0;
        }
        
        body {
            font: 12px/1.5 Tahoma;
        }
        
        center {
            padding-top: 10px;
        }
        
        button {
            cursor: pointer;
        }
        
        #overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: #000;
            opacity: 0.5;
            filter: alpha(opacity=50);
            display: none;
        }
        
        #win {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 400px;
            height: 200px;
            background: #0ff;
            border: 4px solid #f90;
            margin: -102px 0 0 -102px;
            display: none;
        }
        
        h2 {
            font-size: 12px;
            text-align: right;
            background: #fc0;
            border-bottom: 3px solid #f90;
            padding: 0 2px;
        }
        
        h2 span {
            color: #f90;
            cursor: pointer;
            background: #fff;
            border: 1px solid #f90;
            padding: 0 2px;
        }
    </style>

</head>

<body>
    <div id="overlay"></div>
    <div id="win">
        <h2><span id="close">x</span></h2>
    </div>
    <center><button>弹出层</button></center>
</body>

</html>
<script>
    var fds = document.getElementById("win");
    var axp = document.getElementById("overlay");
    var aaa = document.getElementsByTagName("button")[0];
    var oClose = document.getElementById("close");
    aaa.onclick = function() {
        fds.style.display = "block";
        axp.style.display = "block";
    }
    oClose.onclick = function() {
        fds.style.display = "none";
        axp.style.display = "none";
    }
</script>